package com.ziyia.a281;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void imagetoast(View view) {
        Toast toast = new Toast(this);
        toast.setGravity(Gravity.CENTER, 0, 0);

        ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.ic_launcher_background);
        imageView.setMaxWidth(50);
        imageView.setMaxHeight(50);

        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.addView(imageView);

        TextView textView = new TextView(this);
        textView.setText("带图片的Toast");
        textView.setTextSize(12f);
        textView.setTextColor(Color.RED);

        linearLayout.addView(textView);

        toast.setView(linearLayout);

        toast.show();
    }

    public void toast(View view) {
        Toast.makeText(this, "toast", Toast.LENGTH_SHORT).show();
    }
}